package com.qf.test.Controller;

import com.qf.test.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/login")
public class loginController {
    private Map<User, String> map = new HashMap<>();
    @Autowired
    private User user01;
    @Autowired
    private User user02;

    @RequestMapping("/test")
    public String login( String value, HttpSession session, String kapchar) {
             map.put(user01, null);
             map.put(user02, null);

            Set<User> users = map.keySet();
            for (User user1 : users) {
                if (user1.getUsername().equals(value)) {
                    return "0";
                }
            }

        return "1";


    }
    @RequestMapping("/test1")
    public  String login1(User user, HttpSession session, String kapchar){
        map.put(user,null);
        String captcha =(String) session.getAttribute("captcha");
        if (kapchar.equals(captcha)){
            return "ok";
        }
        return "false";
        }

}
